package com.hfi.ood.atmsimulator.transaction;

import com.hfi.ood.atmsimulator.Atm;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;

/**
 * @author ChangLiang
 * @date 2020/5/21
 */
public class DepositTx implements Transaction {

    private Money userMoney;

    @Override
    public boolean preProcess(Atm atm) {
        atm.display("please input deposit money amount");
        String moneyAmount = atm.readInput();
        // check atm has enough money
        userMoney = Money.of(CurrencyUnit.of("CNY"), Double.valueOf(moneyAmount));
        String s = atm.doDeposit(userMoney);
        atm.display(s);
        return true;
    }

    @Override
    public void doTransaction(Atm atm) {
        String bankResult = atm.getBankProxy().doDepositTx(this);
        atm.display(bankResult);
    }

    @Override
    public boolean postProcess(Atm atm) {
        return false;
    }

    @Override
    public String toString() {
        return "DepositTx{" +
                "userMoney=" + userMoney +
                '}';
    }
}
